#include <iostream>
#include <cstdio>
#define int long long
#define file
using namespace std;
int t, n, a[200003], b[200003];
signed main()
{
#ifdef file
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
#endif
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 0; i < 200003; i++)
            b[i] = 0;
        int mx = -1;
        do
        {
            int cnt = 0;
            for (int i = 2; i <= n; i++)
            {
                for (int j = i - 1; j >= 1; j--)
                    if (b[j] == b[i])
                    {
                        if (a[j] == a[i])
                            cnt += a[i];
                        break;
                    }
            }
            mx = max(mx, cnt);
            b[n]++;
            for (int i = n; i >= 0; i--)
            {
                if (b[i] > 1)
                {
                    b[i] = 0;
                    b[i - 1]++;
                }
                else
                    break;
            }
        }
        while (!b[0]);
        cout << mx << endl;
    }
    return 0;
}
